package com.qf.service;

import com.qf.dao.UserDao;
import com.qf.pojo.User;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.ArrayList;
import java.util.List;

/**
 * @author
 */
public class UserServiceImpl1 implements UserService {

    //注入全局属性
    private UserDao userDao;

    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        System.out.println("======UserServiceImpl1的set注入方法执行===========");
        this.userDao = userDao;
    }

    /**
     * 无参数构造方法
     */
    public UserServiceImpl1() {
        System.out.println("=======UserServiceImpl1执行构造======");
    }

    /**
     * 初始化
     */
    @PostConstruct
    public void init() {
        System.out.println("===UserServiceImpl1初始化init=====");
    }

    /**
     * 销毁
     */
    @PreDestroy
    public void destroy() {
        System.out.println("====UserServiceImpl1销毁 destroy=========");
    }

    /**
     * 业务方法
     */
    @Override
    public void registUser() {

        userDao.insertUser();
        System.out.println("======UserService接口的第一种实现类=============");
    }

    @Override
    public List<User> findUserAll() {

        System.out.println("======UserServiceImpl1执行了findUserAll方法=======");

        return new ArrayList<User>();
    }

    @Override
    public void insertUser(User user) {
        System.out.println("======UserServiceImpl1执行了insertUser方法=======");
    }

    @Override
    public void updateUser(User user) {
        System.out.println("======UserServiceImpl1执行了updateUser方法=======");

    }

    @Override
    public void deleteUser(Integer id) {
        System.out.println("======UserServiceImpl1执行了deleteUser方法=======");
        //模拟发生异常
        int i =1/0;
    }

}
